package com.healthyeating.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.healthyeating.common.annotation.Log;
import com.healthyeating.common.core.controller.BaseController;
import com.healthyeating.common.core.domain.AjaxResult;
import com.healthyeating.common.enums.BusinessType;
import com.healthyeating.manage.domain.Physical;
import com.healthyeating.manage.service.IPhysicalService;
import com.healthyeating.common.utils.poi.ExcelUtil;
import com.healthyeating.common.core.page.TableDataInfo;

/**
 * 身体管理Controller
 * 
 * @author 段奇乐
 * @date 2025-03-20
 */
@RestController
@RequestMapping("/manage/physical")
public class PhysicalController extends BaseController
{
    @Autowired
    private IPhysicalService physicalService;

    /**
     * 查询身体管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:physical:list')")
    @GetMapping("/list")
    public TableDataInfo list(Physical physical)
    {
        startPage();
        List<Physical> list = physicalService.selectPhysicalList(physical);
        return getDataTable(list);
    }

    /**
     * 导出身体管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:physical:export')")
    @Log(title = "身体管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Physical physical)
    {
        List<Physical> list = physicalService.selectPhysicalList(physical);
        ExcelUtil<Physical> util = new ExcelUtil<Physical>(Physical.class);
        util.exportExcel(response, list, "身体管理数据");
    }

    /**
     * 获取身体管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:physical:query')")
    @GetMapping(value = "/{physicalId}")
    public AjaxResult getInfo(@PathVariable("physicalId") Long physicalId)
    {
        return success(physicalService.selectPhysicalByPhysicalId(physicalId));
    }

    /**
     * 新增身体管理
     */
    @PreAuthorize("@ss.hasPermi('manage:physical:add')")
    @Log(title = "身体管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Physical physical)
    {
        return toAjax(physicalService.insertPhysical(physical));
    }

    /**
     * 修改身体管理
     */
    @PreAuthorize("@ss.hasPermi('manage:physical:edit')")
    @Log(title = "身体管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Physical physical)
    {
        return toAjax(physicalService.updatePhysical(physical));
    }

    /**
     * 删除身体管理
     */
    @PreAuthorize("@ss.hasPermi('manage:physical:remove')")
    @Log(title = "身体管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{physicalIds}")
    public AjaxResult remove(@PathVariable Long[] physicalIds)
    {
        return toAjax(physicalService.deletePhysicalByPhysicalIds(physicalIds));
    }
}
